package com.jprocms.module.cms.dal.mysql.task;

import com.jpro.framework.common.pojo.PageResult;
import com.jpro.framework.mybatis.core.mapper.BaseMapperX;
import com.jpro.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.jprocms.module.cms.controller.admin.task.vo.TaskExportReqVO;
import com.jprocms.module.cms.controller.admin.task.vo.TaskPageReqVO;
import com.jprocms.module.cms.dal.dataobject.task.TaskDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 任务 Mapper
 *
 * @author JPROCMS4444
 */
@Mapper
public interface TaskMapper extends BaseMapperX<TaskDO> {

    default PageResult<TaskDO> selectPage(TaskPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TaskDO>()
                .eqIfPresent(TaskDO::getSiteId, reqVO.getSiteId())
                .eqIfPresent(TaskDO::getUserId, reqVO.getUserId())
                .likeIfPresent(TaskDO::getName, reqVO.getName())
                .betweenIfPresent(TaskDO::getBeginTime, reqVO.getBeginTime())
                .betweenIfPresent(TaskDO::getEndTime, reqVO.getEndTime())
                .eqIfPresent(TaskDO::getCurrentNum, reqVO.getCurrentNum())
                .eqIfPresent(TaskDO::getTotalNum, reqVO.getTotalNum())
                .eqIfPresent(TaskDO::getTaskType, reqVO.getTaskType())
                .eqIfPresent(TaskDO::getStatus, reqVO.getStatus())
                .eqIfPresent(TaskDO::getErrorMsg, reqVO.getErrorMsg())
                .orderByDesc(TaskDO::getId));
    }

    default List<TaskDO> selectList(TaskExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<TaskDO>()
                .eqIfPresent(TaskDO::getSiteId, reqVO.getSiteId())
                .eqIfPresent(TaskDO::getUserId, reqVO.getUserId())
                .likeIfPresent(TaskDO::getName, reqVO.getName())
                .betweenIfPresent(TaskDO::getBeginTime, reqVO.getBeginTime())
                .betweenIfPresent(TaskDO::getEndTime, reqVO.getEndTime())
                .eqIfPresent(TaskDO::getCurrentNum, reqVO.getCurrentNum())
                .eqIfPresent(TaskDO::getTotalNum, reqVO.getTotalNum())
                .eqIfPresent(TaskDO::getTaskType, reqVO.getTaskType())
                .eqIfPresent(TaskDO::getStatus, reqVO.getStatus())
                .eqIfPresent(TaskDO::getErrorMsg, reqVO.getErrorMsg())
                .orderByDesc(TaskDO::getId));
    }

}
